<template>
  <div class="map-level">
    <div class="header">
      <div class="header-left">
        <div class="date-info">
          <span>{{ state.weekDay }}</span>
          <span>{{ state.dateStr }}</span>
          <span>{{ state.timeStr }}</span>
        </div>
      </div>
      <div class="header-center">
        <div class="title-container">
          <div class="title">智慧文旅应用监测大屏</div>
        </div>
      </div>
      <div class="header-right">
        <div class="weather-info">
          <span>今日气温: {{ state.temperature }}℃</span>
          <span>{{ state.weather }}</span>
          <span class="weather-icon"></span>
        </div>
      </div>
    </div>
    
    <div class="left-column">
      <!-- 添加旅游人数接待情况图表 -->
      <div class="chart-container sales-chart-container">
        <div class="chart-title">旅游人数接待情况</div>
        <div id="salesChart" class="chart-content"></div>
      </div>
      
      <!-- 添加景区质量情况图表 -->
      <div class="chart-container quality-chart-container">
        <div class="chart-title">景区质量情况</div>
        <div id="qualityPieChart" class="chart-content"></div>
      </div>
      
      <!-- 添加热门景区表格 -->
      <div class="table-container inventory-container">
        <div class="table-header">热门景区</div>
        <div class="table-content">
          <table class="table-fixed-header">
            <thead>
              <tr>
                <th>景区名称</th>
                <th>县区</th>
                <th>等级</th>
              </tr>
            </thead>
          </table>
          <div class="scrolling-container">
            <table class="scrolling-table">
              <tbody>
                <tr v-for="(spot, index) in hotScenicSpots" :key="index" class="scenic-row">
                  <td>{{ spot.name }}</td>
                  <td>{{ spot.area }}</td>
                  <td :class="spot.levelClass">{{ spot.level }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 添加文旅发展水平雷达图 -->
    <div class="chart-container tourism-chart-container">
      <div class="chart-title">西宁市文旅发展水平</div>
      <div id="tourismRevenueChart" class="chart-content"></div>
    </div>

    <!-- 添加推荐路线模块 -->
    <div class="routes-container" v-if="state.currentRoute">
      <div class="routes-header">推荐路线</div>
      <div class="routes-content">
        <div class="route-title">{{ state.currentRoute.title }}</div>
        <div class="route-subtitle">{{ state.currentRoute.subtitle }}</div>
        <div class="route-plan">
          <div v-for="day in state.currentRoute.days" :key="day.day" class="day-plan">
            <strong v-html="`${day.day}：${day.title}`"></strong>
            <p v-html="day.plan"></p>
          </div>
        </div>
      </div>
      <div class="route-pagination">
        <span
          v-for="(route, index) in recommendedRoutes"
          :key="index"
          class="dot"
          :class="{ 'active': state.currentRouteIndex === index }"
          @click="switchToRoute(index)"
        ></span>
      </div>
    </div>

    <canvas id="canvas"></canvas>
    <div class="return-btn" @click="goBack">返回上一级</div>
  </div>
</template>

<script setup>
// 这里保持原有的JavaScript逻辑不变
import { onMounted, ref, onBeforeUnmount, reactive, computed } from "vue"
import { World } from "./map"
import * as echarts from 'echarts'
import axios from 'axios'
import { getTouristStatistics, getHotScenicSpots, getTouristAttractionsType } from '../../api'

// 保持原有的所有JavaScript代码...
// (为了简洁，这里省略了JavaScript部分，实际使用时需要复制原文件的完整script部分)
</script>

<style lang="scss">
// CSS变量定义
:root {
  --container-padding: clamp(10px, 1.5vw, 30px);
  --header-height: clamp(60px, 6vh, 100px);
  --chart-height: clamp(200px, 30vh, 350px);
  --left-width: clamp(300px, 28vw, 450px);
  --right-width: clamp(320px, 30vw, 500px);
  --font-size-title: clamp(20px, 3vw, 48px);
  --font-size-large: clamp(14px, 1.4vw, 22px);
  --font-size-medium: clamp(12px, 1.2vw, 18px);
  --font-size-small: clamp(10px, 1vw, 14px);
  --font-size-tiny: clamp(9px, 0.9vw, 12px);
  --border-radius: 4px;
  --primary-color: #2bc4dc;
  --bg-color: rgba(0, 14, 36, 0.7);
  --bg-dark: rgba(0, 10, 30, 0.9);
}

.map-level {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  overflow: hidden;
  
  #canvas {
    width: 100%;
    height: 100%;
    background: #000;
  }
  
  // 响应式缩放
  @media screen and (max-width: 1920px) and (min-width: 1600px) {
    transform: scale(0.95);
    transform-origin: center center;
  }
  
  @media screen and (max-width: 1600px) and (min-width: 1366px) {
    transform: scale(0.85);
    transform-origin: center center;
  }
  
  @media screen and (max-width: 1366px) and (min-width: 1200px) {
    transform: scale(0.75);
    transform-origin: center center;
  }
  
  @media screen and (max-width: 1200px) {
    transform: scale(0.65);
    transform-origin: center center;
  }
  
  @media screen and (max-height: 900px) and (min-height: 768px) {
    transform: scale(0.9);
    transform-origin: center center;
  }
  
  @media screen and (max-height: 768px) {
    transform: scale(0.8);
    transform-origin: center center;
  }
}

// 通用容器样式
.chart-container, .table-container, .routes-container {
  position: relative;
  background: var(--bg-color);
  border: 1px solid var(--primary-color);
  border-radius: var(--border-radius);
  padding: 10px;
  box-shadow: 0 0 10px rgba(46, 229, 255, 0.3);
  box-sizing: border-box;
  
  // 装饰性边角
  &::before, &::after {
    content: '';
    position: absolute;
    width: 15px;
    height: 15px;
  }
  
  &::before {
    top: -1px;
    left: -1px;
    border-top: 2px solid var(--primary-color);
    border-left: 2px solid var(--primary-color);
  }
  
  &::after {
    top: -1px;
    right: -1px;
    border-top: 2px solid var(--primary-color);
    border-right: 2px solid var(--primary-color);
  }
  
  &:before {
    content: '';
    position: absolute;
    bottom: -1px;
    left: -1px;
    width: 15px;
    height: 15px;
    border-bottom: 2px solid var(--primary-color);
    border-left: 2px solid var(--primary-color);
  }
  
  &:after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 15px;
    height: 15px;
    border-bottom: 2px solid var(--primary-color);
    border-right: 2px solid var(--primary-color);
  }
}

// 头部样式
.header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 var(--container-padding);
  color: #fff;
  z-index: 10;
  
  &-left, &-right {
    display: flex;
    align-items: center;
    height: 100%;
    flex: 1;
    justify-content: center;
  }
  
  &-center {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    
    .title-container {
      display: flex;
      align-items: center;
      justify-content: center;
      
      .title {
        font-size: var(--font-size-title);
        font-weight: bold;
        color: #fff;
        text-shadow: 0 0 10px rgba(46, 229, 255, 0.8);
        letter-spacing: clamp(2px, 0.3vw, 6px);
        white-space: nowrap;
        animation: titleGlow 2s infinite alternate;
      }
    }
  }
  
  .date-info, .weather-info {
    position: relative;
    padding: 8px 12px;
    background: var(--bg-color);
    border: 1px solid var(--primary-color);
    border-radius: var(--border-radius);
    box-shadow: 0 0 10px rgba(46, 229, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    max-width: 400px;
    
    span {
      margin: 0 0.5vw;
      font-size: var(--font-size-small);
      text-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
      white-space: nowrap;
    }
  }
}

// 左侧列布局
.left-column {
  position: absolute;
  left: var(--container-padding);
  top: calc(var(--header-height) + 10px);
  bottom: var(--container-padding);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 10;
  width: var(--left-width);
  gap: 15px;
}

// 图表容器
.sales-chart-container,
.quality-chart-container {
  height: var(--chart-height);
  flex: 1;
}

.tourism-chart-container {
  position: absolute;
  top: calc(var(--header-height) + 10px);
  right: var(--container-padding);
  width: var(--right-width);
  height: var(--chart-height);
  z-index: 10;
}

// 表格容器
.inventory-container {
  height: var(--chart-height);
  flex: 1;
  background: var(--bg-dark);
  padding: 0;
  
  .table-header {
    font-size: var(--font-size-large);
    color: #fff;
    text-align: left;
    margin: 0;
    padding: 8px 15px;
    background: linear-gradient(to right, rgba(43, 196, 220, 0.3), transparent);
    border-bottom: 1px solid var(--primary-color);
  }
  
  .table-content {
    height: calc(100% - 40px);
    
    .table-fixed-header {
      width: 100%;
      border-collapse: collapse;
      table-layout: fixed;
      
      th {
        padding: 8px;
        text-align: left;
        color: #fff;
        font-weight: normal;
        font-size: var(--font-size-small);
        white-space: nowrap;
        border-bottom: 1px solid var(--primary-color);
        
        &:nth-child(1) { width: 60%; }
        &:nth-child(2) { width: 25%; }
        &:nth-child(3) { width: 15%; text-align: center; }
      }
    }
    
    .scrolling-container {
      height: calc(100% - 40px);
      overflow: hidden;
      
      .scrolling-table {
        width: 100%;
        border-collapse: collapse;
        table-layout: fixed;
        
        td {
          padding: 8px;
          font-size: var(--font-size-tiny);
          color: #fff;
          vertical-align: top;
          word-wrap: break-word;
          
          &:nth-child(1) { width: 60%; }
          &:nth-child(2) { width: 25%; }
          &:nth-child(3) { 
            width: 15%; 
            text-align: center;
            
            &.level-5a { color: #ffc107; font-weight: bold; }
            &.level-4a { color: #28a745; font-weight: bold; }
            &.level-3a { color: #007bff; font-weight: bold; }
          }
        }
        
        tr {
          border-bottom: 1px solid rgba(43, 196, 220, 0.2);
          transition: all 0.3s ease;
          
          &:hover {
            background: rgba(43, 196, 220, 0.1);
          }
        }
      }
    }
  }
}

// 路线容器
.routes-container {
  position: absolute;
  bottom: var(--container-padding);
  right: var(--container-padding);
  width: var(--right-width);
  background: var(--bg-dark);
  z-index: 10;
  padding: 0;
  
  .routes-header {
    font-size: var(--font-size-large);
    color: #fff;
    text-align: left;
    margin: 0;
    padding: 8px 15px;
    background: linear-gradient(to right, rgba(43, 196, 220, 0.3), transparent);
    border-bottom: 1px solid var(--primary-color);
  }
  
  .routes-content {
    padding: 15px;
    height: clamp(300px, 40vh, 500px);
    overflow-y: hidden;
    color: #fff;
    
    .route-title {
      font-size: var(--font-size-large);
      font-weight: bold;
      color: #7efbf6;
      margin-bottom: 5px;
    }
    
    .route-subtitle {
      font-size: var(--font-size-small);
      color: #ccc;
      margin-bottom: 15px;
    }
    
    .route-plan {
      .day-plan {
        margin-bottom: 12px;
        
        strong {
          font-size: var(--font-size-small);
          color: var(--primary-color);
          display: block;
          margin-bottom: 6px;
        }
        
        p {
          font-size: var(--font-size-tiny);
          line-height: 1.5;
          margin: 0;
          padding-left: 8px;
          color: #eee;
        }
      }
    }
  }
  
  .route-pagination {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 11;
    
    .dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background-color: rgba(255, 255, 255, 0.4);
      cursor: pointer;
      transition: all 0.3s ease;
      
      &.active {
        background-color: var(--primary-color);
        transform: scale(1.2);
      }
      
      &:hover {
        background-color: rgba(255, 255, 255, 0.7);
      }
    }
  }
}

// 通用标题样式
.chart-title {
  font-size: var(--font-size-medium);
  color: #fff;
  text-align: left;
  margin-bottom: 5px;
  padding: 0 5px;
  border-left: 2px solid var(--primary-color);
}

// 图表内容区域
.chart-content {
  width: 100%;
  height: calc(100% - 30px);
}

// 返回按钮
.return-btn {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  padding: 5px 20px;
  color: #fff;
  border: 1px solid var(--primary-color);
  background: var(--bg-color);
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: var(--font-size-small);
  z-index: 10;
  transition: all 0.3s ease;
  
  &:hover {
    background: rgba(43, 196, 220, 0.2);
    transform: translateX(-50%) scale(1.05);
  }
}

// 动画效果
@keyframes titleGlow {
  0% {
    text-shadow: 0 0 10px rgba(46, 229, 255, 0.8), 0 0 20px rgba(46, 229, 255, 0.4);
  }
  100% {
    text-shadow: 0 0 15px rgba(46, 229, 255, 0.9), 0 0 30px rgba(46, 229, 255, 0.5), 0 0 40px rgba(46, 229, 255, 0.3);
  }
}

// 移动端适配
@media screen and (max-width: 768px) {
  .map-level {
    transform: scale(0.5);
    transform-origin: center center;
  }
  
  .left-column {
    width: 45vw;
  }
  
  .tourism-chart-container,
  .routes-container {
    width: 45vw;
  }
}

// 超宽屏适配
@media screen and (min-width: 2560px) {
  .map-level {
    transform: scale(1.1);
    transform-origin: center center;
  }
}
</style>